package com.youdianda.controller;


import com.youdianda.dto.RolePageQueryDTO;
import com.youdianda.dto.RoleUpdateDTO;
import com.youdianda.result.Result;
import com.youdianda.service.ISysRoleService;
import com.youdianda.vo.RoleDetailsVO;
import com.youdianda.vo.RolePageQueryVO;
import com.youdianda.vo.RoleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author mosen
 * @since 2023-05-15
 */
@RestController
@RequestMapping("/sys_role")
@Slf4j
public class SysRoleController {

    @Autowired
    private ISysRoleService iSysRoleService;

    /**角色列表分页*/
    @GetMapping("/list")
    public Result<RolePageQueryVO> listRole(RolePageQueryDTO rolePageQueryDTO){
        log.warn(rolePageQueryDTO.toString());
        RolePageQueryVO rolePageQueryVO= iSysRoleService.listRole(rolePageQueryDTO);
        return Result.success(rolePageQueryVO);
    }

    /**角色列表全部*/
    @GetMapping("/allData")
    public Result<List<RoleVO>> listAllRole(){
        return iSysRoleService.listAllRole();
    }

    /**角色详情*/
    @GetMapping("/rowInfo")
    public Result<RoleDetailsVO> getRoleById(@RequestParam String id){
        return iSysRoleService.getRoleById(id);
    }

    /**角色修改*/
    @PostMapping("/update")
    public Result updateRole(@RequestBody RoleUpdateDTO roleUpdateDTO){
        return iSysRoleService.updateRole(roleUpdateDTO);
    }

    /**角色添加*/
    @PostMapping("/add")
    public Result addRole(@RequestBody RoleUpdateDTO roleUpdateDTO){
        log.error("接收数据拉！！！！！！！！！！！！！dto是+"+roleUpdateDTO);
        return iSysRoleService.addRole(roleUpdateDTO);
    }

    /**角色删除*/
    @GetMapping("/del")
    private Result deleteRole(@RequestParam String id){
        return iSysRoleService.deleteRole(id);
    }

}
